﻿
using System.ComponentModel.Composition;
using System.Linq;
using System.Web.Mvc;
using CafeOnline.Common;
using CafeOnline.Domain.IRepositories;
using CafeOnline.Domain.Entities;

namespace CafeOnline.Controllers {
    [Export(typeof(IController)), ExportMetadata("Name", ControllerNames.PRODUCT_GROUPS_CONTROLLER)]
    [PartCreationPolicy(CreationPolicy.NonShared)]
    public class ProductGroupController : BaseController {
        [Import]
        private IProductGroupRepository m_productGroupRepository;


        public override ActionResult Index() {

            return base.Index();
        }

        public override ActionResult Create() {
            ViewBag.ProductGroupId = new SelectList(m_productGroupRepository.GetAll().ToList(), "ProductGroupId", "ProductGroupName");
            return base.Create();
        }
        public JsonResult Save(ProductGroup model) {
            if (ModelState.IsValid) {
                m_productGroupRepository.AddNewProductGroup(model);
                return Json("success", JsonRequestBehavior.AllowGet);
            }
            return Json(model);
        }
    }
}
